{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Trabalho de KNN - JADER GOMES"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from sklearn import datasets "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [],
   "source": [
    "class KNNClassifier(object):\n",
    "    def __init__(self, n=1):\n",
    "        self.X_train = None\n",
    "        self.Y_train = None\n",
    "        self.n = n\n",
    "        \n",
    "    def dist_euc(self, a, b):\n",
    "        dist = DistanceMetric.get_metric('euclidean').pairwise([a],[b])[0][0]\n",
    "        return dist\n",
    "    \n",
    "    def closest(self, row, k):\n",
    "        dist = [(self.dist_euc(row, item)) for index,item in enumerate(self.X_train)]\n",
    "        dist.sort(key = lambda x:x[1])\n",
    "        viz = []\n",
    "        for i in range(k):\n",
    "            viz.append(self.Y_train[dist[i][0]])\n",
    "            \n",
    "        classe = Counter(viz).most_common(1)[0][0]\n",
    "        \n",
    "        return classe\n",
    "    \n",
    "    def fit(self, training_data, training_labels):\n",
    "        self.X_train = training_data\n",
    "        self.Y_train = training_labels\n",
    "        \n",
    "    def predict(self, to_classify, k=3):\n",
    "        predictions = []\n",
    "        for row in to_classify:\n",
    "            label = self.closest(row,k)\n",
    "            predictions.append(label)\n",
    "            \n",
    "        return predictions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv('train.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'DataFrame' object has no attribute 'Age'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-5-f01cc7d1df9b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'Age'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mAge\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfillna\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mAge\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmean\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0mdf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwhere\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnotnull\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mf\u001b[0m \u001b[0;32min\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m'Sex'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'Embarked'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m     \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'category'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m     \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcat\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcodes\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/miniconda3/envs/aula/lib/python3.6/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m   3612\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mname\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_info_axis\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   3613\u001b[0m                 \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3614\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   3615\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   3616\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m__setattr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mAttributeError\u001b[0m: 'DataFrame' object has no attribute 'Age'"
     ]
    }
   ],
   "source": [
    "df['Age'] = df.Age.fillna(df.Age.mean())\n",
    "df = df.where((pd.notnull(df)),0)\n",
    "for f in ['Sex','Embarked']:\n",
    "    df[f] = df[f].astype('category')\n",
    "    df[f] = df[f].cat.codes\n",
    "    \n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'DataFrame' object has no attribute 'Age'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-6-f176929d42d8>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'age'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mAge\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfillna\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mAge\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmean\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0mdf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwhere\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnotnull\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mf\u001b[0m \u001b[0;32min\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m'sex'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'embarked'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m     \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'category'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m     \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcat\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcodes\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/miniconda3/envs/aula/lib/python3.6/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m   3612\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mname\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_info_axis\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   3613\u001b[0m                 \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3614\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   3615\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   3616\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m__setattr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mAttributeError\u001b[0m: 'DataFrame' object has no attribute 'Age'"
     ]
    }
   ],
   "source": [
    "df['age'] = df.Age.fillna(df.Age.mean())\n",
    "df = df.where((pd.notnull(df)),0)\n",
    "for f in ['sex','embarked']:\n",
    "    df[f] = df[f].astype('category')\n",
    "    df[f] = df[f].cat.codes\n",
    "    \n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>ticket</th>\n",
       "      <th>fare</th>\n",
       "      <th>cabin</th>\n",
       "      <th>embarked</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Braund, Mr. Owen Harris</td>\n",
       "      <td>1</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>A/5 21171</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n",
       "      <td>0</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>PC 17599</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C85</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>Heikkinen, Miss. Laina</td>\n",
       "      <td>0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>STON/O2. 3101282</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n",
       "      <td>0</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>113803</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>C123</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Allen, Mr. William Henry</td>\n",
       "      <td>1</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>373450</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass                                               name  sex  \\\n",
       "0         0       3                            Braund, Mr. Owen Harris    1   \n",
       "1         1       1  Cumings, Mrs. John Bradley (Florence Briggs Th...    0   \n",
       "2         1       3                             Heikkinen, Miss. Laina    0   \n",
       "3         1       1       Futrelle, Mrs. Jacques Heath (Lily May Peel)    0   \n",
       "4         0       3                           Allen, Mr. William Henry    1   \n",
       "\n",
       "    age  sibsp  parch            ticket     fare cabin  embarked  \n",
       "0  22.0      1      0         A/5 21171   7.2500     0         3  \n",
       "1  38.0      1      0          PC 17599  71.2833   C85         1  \n",
       "2  26.0      0      0  STON/O2. 3101282   7.9250     0         3  \n",
       "3  35.0      1      0            113803  53.1000  C123         3  \n",
       "4  35.0      0      0            373450   8.0500     0         3  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['age'] = df.age.fillna(df.age.mean())\n",
    "df = df.where((pd.notnull(df)),0)\n",
    "for f in ['sex','embarked']:\n",
    "    df[f] = df[f].astype('category')\n",
    "    df[f] = df[f].cat.codes\n",
    "    \n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'df' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-1-5cc0934cc03c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdtypes\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m: name 'df' is not defined"
     ]
    }
   ],
   "source": [
    "df.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     survived  pclass                                               name  \\\n",
      "0           0       3                            Braund, Mr. Owen Harris   \n",
      "1           1       1  Cumings, Mrs. John Bradley (Florence Briggs Th...   \n",
      "2           1       3                             Heikkinen, Miss. Laina   \n",
      "3           1       1       Futrelle, Mrs. Jacques Heath (Lily May Peel)   \n",
      "4           0       3                           Allen, Mr. William Henry   \n",
      "5           0       3                                   Moran, Mr. James   \n",
      "6           0       1                            McCarthy, Mr. Timothy J   \n",
      "7           0       3                     Palsson, Master. Gosta Leonard   \n",
      "8           1       3  Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg)   \n",
      "9           1       2                Nasser, Mrs. Nicholas (Adele Achem)   \n",
      "10          1       3                    Sandstrom, Miss. Marguerite Rut   \n",
      "11          1       1                           Bonnell, Miss. Elizabeth   \n",
      "12          0       3                     Saundercock, Mr. William Henry   \n",
      "13          0       3                        Andersson, Mr. Anders Johan   \n",
      "14          0       3               Vestrom, Miss. Hulda Amanda Adolfina   \n",
      "15          1       2                   Hewlett, Mrs. (Mary D Kingcome)    \n",
      "16          0       3                               Rice, Master. Eugene   \n",
      "17          1       2                       Williams, Mr. Charles Eugene   \n",
      "18          0       3  Vander Planke, Mrs. Julius (Emelia Maria Vande...   \n",
      "19          1       3                            Masselmani, Mrs. Fatima   \n",
      "20          0       2                               Fynney, Mr. Joseph J   \n",
      "21          1       2                              Beesley, Mr. Lawrence   \n",
      "22          1       3                        McGowan, Miss. Anna \"Annie\"   \n",
      "23          1       1                       Sloper, Mr. William Thompson   \n",
      "24          0       3                      Palsson, Miss. Torborg Danira   \n",
      "25          1       3  Asplund, Mrs. Carl Oscar (Selma Augusta Emilia...   \n",
      "26          0       3                            Emir, Mr. Farred Chehab   \n",
      "27          0       1                     Fortune, Mr. Charles Alexander   \n",
      "28          1       3                      O'Dwyer, Miss. Ellen \"Nellie\"   \n",
      "29          0       3                                Todoroff, Mr. Lalio   \n",
      "..        ...     ...                                                ...   \n",
      "861         0       2                        Giles, Mr. Frederick Edward   \n",
      "862         1       1  Swift, Mrs. Frederick Joel (Margaret Welles Ba...   \n",
      "863         0       3                  Sage, Miss. Dorothy Edith \"Dolly\"   \n",
      "864         0       2                             Gill, Mr. John William   \n",
      "865         1       2                           Bystrom, Mrs. (Karolina)   \n",
      "866         1       2                       Duran y More, Miss. Asuncion   \n",
      "867         0       1               Roebling, Mr. Washington Augustus II   \n",
      "868         0       3                        van Melkebeke, Mr. Philemon   \n",
      "869         1       3                    Johnson, Master. Harold Theodor   \n",
      "870         0       3                                  Balkic, Mr. Cerin   \n",
      "871         1       1   Beckwith, Mrs. Richard Leonard (Sallie Monypeny)   \n",
      "872         0       1                           Carlsson, Mr. Frans Olof   \n",
      "873         0       3                        Vander Cruyssen, Mr. Victor   \n",
      "874         1       2              Abelson, Mrs. Samuel (Hannah Wizosky)   \n",
      "875         1       3                   Najib, Miss. Adele Kiamie \"Jane\"   \n",
      "876         0       3                      Gustafsson, Mr. Alfred Ossian   \n",
      "877         0       3                               Petroff, Mr. Nedelio   \n",
      "878         0       3                                 Laleff, Mr. Kristo   \n",
      "879         1       1      Potter, Mrs. Thomas Jr (Lily Alexenia Wilson)   \n",
      "880         1       2       Shelley, Mrs. William (Imanita Parrish Hall)   \n",
      "881         0       3                                 Markun, Mr. Johann   \n",
      "882         0       3                       Dahlberg, Miss. Gerda Ulrika   \n",
      "883         0       2                      Banfield, Mr. Frederick James   \n",
      "884         0       3                             Sutehall, Mr. Henry Jr   \n",
      "885         0       3               Rice, Mrs. William (Margaret Norton)   \n",
      "886         0       2                              Montvila, Rev. Juozas   \n",
      "887         1       1                       Graham, Miss. Margaret Edith   \n",
      "888         0       3           Johnston, Miss. Catherine Helen \"Carrie\"   \n",
      "889         1       1                              Behr, Mr. Karl Howell   \n",
      "890         0       3                                Dooley, Mr. Patrick   \n",
      "\n",
      "        sex   age  sibsp  parch            ticket      fare        cabin  \\\n",
      "0      male  22.0      1      0         A/5 21171    7.2500          NaN   \n",
      "1    female  38.0      1      0          PC 17599   71.2833          C85   \n",
      "2    female  26.0      0      0  STON/O2. 3101282    7.9250          NaN   \n",
      "3    female  35.0      1      0            113803   53.1000         C123   \n",
      "4      male  35.0      0      0            373450    8.0500          NaN   \n",
      "5      male   NaN      0      0            330877    8.4583          NaN   \n",
      "6      male  54.0      0      0             17463   51.8625          E46   \n",
      "7      male   2.0      3      1            349909   21.0750          NaN   \n",
      "8    female  27.0      0      2            347742   11.1333          NaN   \n",
      "9    female  14.0      1      0            237736   30.0708          NaN   \n",
      "10   female   4.0      1      1           PP 9549   16.7000           G6   \n",
      "11   female  58.0      0      0            113783   26.5500         C103   \n",
      "12     male  20.0      0      0         A/5. 2151    8.0500          NaN   \n",
      "13     male  39.0      1      5            347082   31.2750          NaN   \n",
      "14   female  14.0      0      0            350406    7.8542          NaN   \n",
      "15   female  55.0      0      0            248706   16.0000          NaN   \n",
      "16     male   2.0      4      1            382652   29.1250          NaN   \n",
      "17     male   NaN      0      0            244373   13.0000          NaN   \n",
      "18   female  31.0      1      0            345763   18.0000          NaN   \n",
      "19   female   NaN      0      0              2649    7.2250          NaN   \n",
      "20     male  35.0      0      0            239865   26.0000          NaN   \n",
      "21     male  34.0      0      0            248698   13.0000          D56   \n",
      "22   female  15.0      0      0            330923    8.0292          NaN   \n",
      "23     male  28.0      0      0            113788   35.5000           A6   \n",
      "24   female   8.0      3      1            349909   21.0750          NaN   \n",
      "25   female  38.0      1      5            347077   31.3875          NaN   \n",
      "26     male   NaN      0      0              2631    7.2250          NaN   \n",
      "27     male  19.0      3      2             19950  263.0000  C23 C25 C27   \n",
      "28   female   NaN      0      0            330959    7.8792          NaN   \n",
      "29     male   NaN      0      0            349216    7.8958          NaN   \n",
      "..      ...   ...    ...    ...               ...       ...          ...   \n",
      "861    male  21.0      1      0             28134   11.5000          NaN   \n",
      "862  female  48.0      0      0             17466   25.9292          D17   \n",
      "863  female   NaN      8      2          CA. 2343   69.5500          NaN   \n",
      "864    male  24.0      0      0            233866   13.0000          NaN   \n",
      "865  female  42.0      0      0            236852   13.0000          NaN   \n",
      "866  female  27.0      1      0     SC/PARIS 2149   13.8583          NaN   \n",
      "867    male  31.0      0      0          PC 17590   50.4958          A24   \n",
      "868    male   NaN      0      0            345777    9.5000          NaN   \n",
      "869    male   4.0      1      1            347742   11.1333          NaN   \n",
      "870    male  26.0      0      0            349248    7.8958          NaN   \n",
      "871  female  47.0      1      1             11751   52.5542          D35   \n",
      "872    male  33.0      0      0               695    5.0000  B51 B53 B55   \n",
      "873    male  47.0      0      0            345765    9.0000          NaN   \n",
      "874  female  28.0      1      0         P/PP 3381   24.0000          NaN   \n",
      "875  female  15.0      0      0              2667    7.2250          NaN   \n",
      "876    male  20.0      0      0              7534    9.8458          NaN   \n",
      "877    male  19.0      0      0            349212    7.8958          NaN   \n",
      "878    male   NaN      0      0            349217    7.8958          NaN   \n",
      "879  female  56.0      0      1             11767   83.1583          C50   \n",
      "880  female  25.0      0      1            230433   26.0000          NaN   \n",
      "881    male  33.0      0      0            349257    7.8958          NaN   \n",
      "882  female  22.0      0      0              7552   10.5167          NaN   \n",
      "883    male  28.0      0      0  C.A./SOTON 34068   10.5000          NaN   \n",
      "884    male  25.0      0      0   SOTON/OQ 392076    7.0500          NaN   \n",
      "885  female  39.0      0      5            382652   29.1250          NaN   \n",
      "886    male  27.0      0      0            211536   13.0000          NaN   \n",
      "887  female  19.0      0      0            112053   30.0000          B42   \n",
      "888  female   NaN      1      2        W./C. 6607   23.4500          NaN   \n",
      "889    male  26.0      0      0            111369   30.0000         C148   \n",
      "890    male  32.0      0      0            370376    7.7500          NaN   \n",
      "\n",
      "    embarked  \n",
      "0          S  \n",
      "1          C  \n",
      "2          S  \n",
      "3          S  \n",
      "4          S  \n",
      "5          Q  \n",
      "6          S  \n",
      "7          S  \n",
      "8          S  \n",
      "9          C  \n",
      "10         S  \n",
      "11         S  \n",
      "12         S  \n",
      "13         S  \n",
      "14         S  \n",
      "15         S  \n",
      "16         Q  \n",
      "17         S  \n",
      "18         S  \n",
      "19         C  \n",
      "20         S  \n",
      "21         S  \n",
      "22         Q  \n",
      "23         S  \n",
      "24         S  \n",
      "25         S  \n",
      "26         C  \n",
      "27         S  \n",
      "28         Q  \n",
      "29         S  \n",
      "..       ...  \n",
      "861        S  \n",
      "862        S  \n",
      "863        S  \n",
      "864        S  \n",
      "865        S  \n",
      "866        C  \n",
      "867        S  \n",
      "868        S  \n",
      "869        S  \n",
      "870        S  \n",
      "871        S  \n",
      "872        S  \n",
      "873        S  \n",
      "874        C  \n",
      "875        C  \n",
      "876        S  \n",
      "877        S  \n",
      "878        S  \n",
      "879        C  \n",
      "880        S  \n",
      "881        S  \n",
      "882        S  \n",
      "883        S  \n",
      "884        S  \n",
      "885        Q  \n",
      "886        S  \n",
      "887        S  \n",
      "888        S  \n",
      "889        C  \n",
      "890        Q  \n",
      "\n",
      "[891 rows x 11 columns]\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv('train.csv')\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     survived  pclass                                               name  \\\n",
      "0           0       3                            Braund, Mr. Owen Harris   \n",
      "1           1       1  Cumings, Mrs. John Bradley (Florence Briggs Th...   \n",
      "2           1       3                             Heikkinen, Miss. Laina   \n",
      "3           1       1       Futrelle, Mrs. Jacques Heath (Lily May Peel)   \n",
      "4           0       3                           Allen, Mr. William Henry   \n",
      "5           0       3                                   Moran, Mr. James   \n",
      "6           0       1                            McCarthy, Mr. Timothy J   \n",
      "7           0       3                     Palsson, Master. Gosta Leonard   \n",
      "8           1       3  Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg)   \n",
      "9           1       2                Nasser, Mrs. Nicholas (Adele Achem)   \n",
      "10          1       3                    Sandstrom, Miss. Marguerite Rut   \n",
      "11          1       1                           Bonnell, Miss. Elizabeth   \n",
      "12          0       3                     Saundercock, Mr. William Henry   \n",
      "13          0       3                        Andersson, Mr. Anders Johan   \n",
      "14          0       3               Vestrom, Miss. Hulda Amanda Adolfina   \n",
      "15          1       2                   Hewlett, Mrs. (Mary D Kingcome)    \n",
      "16          0       3                               Rice, Master. Eugene   \n",
      "17          1       2                       Williams, Mr. Charles Eugene   \n",
      "18          0       3  Vander Planke, Mrs. Julius (Emelia Maria Vande...   \n",
      "19          1       3                            Masselmani, Mrs. Fatima   \n",
      "20          0       2                               Fynney, Mr. Joseph J   \n",
      "21          1       2                              Beesley, Mr. Lawrence   \n",
      "22          1       3                        McGowan, Miss. Anna \"Annie\"   \n",
      "23          1       1                       Sloper, Mr. William Thompson   \n",
      "24          0       3                      Palsson, Miss. Torborg Danira   \n",
      "25          1       3  Asplund, Mrs. Carl Oscar (Selma Augusta Emilia...   \n",
      "26          0       3                            Emir, Mr. Farred Chehab   \n",
      "27          0       1                     Fortune, Mr. Charles Alexander   \n",
      "28          1       3                      O'Dwyer, Miss. Ellen \"Nellie\"   \n",
      "29          0       3                                Todoroff, Mr. Lalio   \n",
      "..        ...     ...                                                ...   \n",
      "861         0       2                        Giles, Mr. Frederick Edward   \n",
      "862         1       1  Swift, Mrs. Frederick Joel (Margaret Welles Ba...   \n",
      "863         0       3                  Sage, Miss. Dorothy Edith \"Dolly\"   \n",
      "864         0       2                             Gill, Mr. John William   \n",
      "865         1       2                           Bystrom, Mrs. (Karolina)   \n",
      "866         1       2                       Duran y More, Miss. Asuncion   \n",
      "867         0       1               Roebling, Mr. Washington Augustus II   \n",
      "868         0       3                        van Melkebeke, Mr. Philemon   \n",
      "869         1       3                    Johnson, Master. Harold Theodor   \n",
      "870         0       3                                  Balkic, Mr. Cerin   \n",
      "871         1       1   Beckwith, Mrs. Richard Leonard (Sallie Monypeny)   \n",
      "872         0       1                           Carlsson, Mr. Frans Olof   \n",
      "873         0       3                        Vander Cruyssen, Mr. Victor   \n",
      "874         1       2              Abelson, Mrs. Samuel (Hannah Wizosky)   \n",
      "875         1       3                   Najib, Miss. Adele Kiamie \"Jane\"   \n",
      "876         0       3                      Gustafsson, Mr. Alfred Ossian   \n",
      "877         0       3                               Petroff, Mr. Nedelio   \n",
      "878         0       3                                 Laleff, Mr. Kristo   \n",
      "879         1       1      Potter, Mrs. Thomas Jr (Lily Alexenia Wilson)   \n",
      "880         1       2       Shelley, Mrs. William (Imanita Parrish Hall)   \n",
      "881         0       3                                 Markun, Mr. Johann   \n",
      "882         0       3                       Dahlberg, Miss. Gerda Ulrika   \n",
      "883         0       2                      Banfield, Mr. Frederick James   \n",
      "884         0       3                             Sutehall, Mr. Henry Jr   \n",
      "885         0       3               Rice, Mrs. William (Margaret Norton)   \n",
      "886         0       2                              Montvila, Rev. Juozas   \n",
      "887         1       1                       Graham, Miss. Margaret Edith   \n",
      "888         0       3           Johnston, Miss. Catherine Helen \"Carrie\"   \n",
      "889         1       1                              Behr, Mr. Karl Howell   \n",
      "890         0       3                                Dooley, Mr. Patrick   \n",
      "\n",
      "        sex   age  sibsp  parch            ticket      fare        cabin  \\\n",
      "0      male  22.0      1      0         A/5 21171    7.2500          NaN   \n",
      "1    female  38.0      1      0          PC 17599   71.2833          C85   \n",
      "2    female  26.0      0      0  STON/O2. 3101282    7.9250          NaN   \n",
      "3    female  35.0      1      0            113803   53.1000         C123   \n",
      "4      male  35.0      0      0            373450    8.0500          NaN   \n",
      "5      male   NaN      0      0            330877    8.4583          NaN   \n",
      "6      male  54.0      0      0             17463   51.8625          E46   \n",
      "7      male   2.0      3      1            349909   21.0750          NaN   \n",
      "8    female  27.0      0      2            347742   11.1333          NaN   \n",
      "9    female  14.0      1      0            237736   30.0708          NaN   \n",
      "10   female   4.0      1      1           PP 9549   16.7000           G6   \n",
      "11   female  58.0      0      0            113783   26.5500         C103   \n",
      "12     male  20.0      0      0         A/5. 2151    8.0500          NaN   \n",
      "13     male  39.0      1      5            347082   31.2750          NaN   \n",
      "14   female  14.0      0      0            350406    7.8542          NaN   \n",
      "15   female  55.0      0      0            248706   16.0000          NaN   \n",
      "16     male   2.0      4      1            382652   29.1250          NaN   \n",
      "17     male   NaN      0      0            244373   13.0000          NaN   \n",
      "18   female  31.0      1      0            345763   18.0000          NaN   \n",
      "19   female   NaN      0      0              2649    7.2250          NaN   \n",
      "20     male  35.0      0      0            239865   26.0000          NaN   \n",
      "21     male  34.0      0      0            248698   13.0000          D56   \n",
      "22   female  15.0      0      0            330923    8.0292          NaN   \n",
      "23     male  28.0      0      0            113788   35.5000           A6   \n",
      "24   female   8.0      3      1            349909   21.0750          NaN   \n",
      "25   female  38.0      1      5            347077   31.3875          NaN   \n",
      "26     male   NaN      0      0              2631    7.2250          NaN   \n",
      "27     male  19.0      3      2             19950  263.0000  C23 C25 C27   \n",
      "28   female   NaN      0      0            330959    7.8792          NaN   \n",
      "29     male   NaN      0      0            349216    7.8958          NaN   \n",
      "..      ...   ...    ...    ...               ...       ...          ...   \n",
      "861    male  21.0      1      0             28134   11.5000          NaN   \n",
      "862  female  48.0      0      0             17466   25.9292          D17   \n",
      "863  female   NaN      8      2          CA. 2343   69.5500          NaN   \n",
      "864    male  24.0      0      0            233866   13.0000          NaN   \n",
      "865  female  42.0      0      0            236852   13.0000          NaN   \n",
      "866  female  27.0      1      0     SC/PARIS 2149   13.8583          NaN   \n",
      "867    male  31.0      0      0          PC 17590   50.4958          A24   \n",
      "868    male   NaN      0      0            345777    9.5000          NaN   \n",
      "869    male   4.0      1      1            347742   11.1333          NaN   \n",
      "870    male  26.0      0      0            349248    7.8958          NaN   \n",
      "871  female  47.0      1      1             11751   52.5542          D35   \n",
      "872    male  33.0      0      0               695    5.0000  B51 B53 B55   \n",
      "873    male  47.0      0      0            345765    9.0000          NaN   \n",
      "874  female  28.0      1      0         P/PP 3381   24.0000          NaN   \n",
      "875  female  15.0      0      0              2667    7.2250          NaN   \n",
      "876    male  20.0      0      0              7534    9.8458          NaN   \n",
      "877    male  19.0      0      0            349212    7.8958          NaN   \n",
      "878    male   NaN      0      0            349217    7.8958          NaN   \n",
      "879  female  56.0      0      1             11767   83.1583          C50   \n",
      "880  female  25.0      0      1            230433   26.0000          NaN   \n",
      "881    male  33.0      0      0            349257    7.8958          NaN   \n",
      "882  female  22.0      0      0              7552   10.5167          NaN   \n",
      "883    male  28.0      0      0  C.A./SOTON 34068   10.5000          NaN   \n",
      "884    male  25.0      0      0   SOTON/OQ 392076    7.0500          NaN   \n",
      "885  female  39.0      0      5            382652   29.1250          NaN   \n",
      "886    male  27.0      0      0            211536   13.0000          NaN   \n",
      "887  female  19.0      0      0            112053   30.0000          B42   \n",
      "888  female   NaN      1      2        W./C. 6607   23.4500          NaN   \n",
      "889    male  26.0      0      0            111369   30.0000         C148   \n",
      "890    male  32.0      0      0            370376    7.7500          NaN   \n",
      "\n",
      "    embarked  \n",
      "0          S  \n",
      "1          C  \n",
      "2          S  \n",
      "3          S  \n",
      "4          S  \n",
      "5          Q  \n",
      "6          S  \n",
      "7          S  \n",
      "8          S  \n",
      "9          C  \n",
      "10         S  \n",
      "11         S  \n",
      "12         S  \n",
      "13         S  \n",
      "14         S  \n",
      "15         S  \n",
      "16         Q  \n",
      "17         S  \n",
      "18         S  \n",
      "19         C  \n",
      "20         S  \n",
      "21         S  \n",
      "22         Q  \n",
      "23         S  \n",
      "24         S  \n",
      "25         S  \n",
      "26         C  \n",
      "27         S  \n",
      "28         Q  \n",
      "29         S  \n",
      "..       ...  \n",
      "861        S  \n",
      "862        S  \n",
      "863        S  \n",
      "864        S  \n",
      "865        S  \n",
      "866        C  \n",
      "867        S  \n",
      "868        S  \n",
      "869        S  \n",
      "870        S  \n",
      "871        S  \n",
      "872        S  \n",
      "873        S  \n",
      "874        C  \n",
      "875        C  \n",
      "876        S  \n",
      "877        S  \n",
      "878        S  \n",
      "879        C  \n",
      "880        S  \n",
      "881        S  \n",
      "882        S  \n",
      "883        S  \n",
      "884        S  \n",
      "885        Q  \n",
      "886        S  \n",
      "887        S  \n",
      "888        S  \n",
      "889        C  \n",
      "890        Q  \n",
      "\n",
      "[891 rows x 11 columns]\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv('train.csv')\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "survived      int64\n",
       "pclass        int64\n",
       "name         object\n",
       "sex          object\n",
       "age         float64\n",
       "sibsp         int64\n",
       "parch         int64\n",
       "ticket       object\n",
       "fare        float64\n",
       "cabin        object\n",
       "embarked     object\n",
       "dtype: object"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>ticket</th>\n",
       "      <th>fare</th>\n",
       "      <th>cabin</th>\n",
       "      <th>embarked</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Braund, Mr. Owen Harris</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>A/5 21171</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>PC 17599</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C85</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>Heikkinen, Miss. Laina</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>STON/O2. 3101282</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>113803</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>C123</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Allen, Mr. William Henry</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>373450</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass                                               name  \\\n",
       "0         0       3                            Braund, Mr. Owen Harris   \n",
       "1         1       1  Cumings, Mrs. John Bradley (Florence Briggs Th...   \n",
       "2         1       3                             Heikkinen, Miss. Laina   \n",
       "3         1       1       Futrelle, Mrs. Jacques Heath (Lily May Peel)   \n",
       "4         0       3                           Allen, Mr. William Henry   \n",
       "\n",
       "      sex   age  sibsp  parch            ticket     fare cabin embarked  \n",
       "0    male  22.0      1      0         A/5 21171   7.2500   NaN        S  \n",
       "1  female  38.0      1      0          PC 17599  71.2833   C85        C  \n",
       "2  female  26.0      0      0  STON/O2. 3101282   7.9250   NaN        S  \n",
       "3  female  35.0      1      0            113803  53.1000  C123        S  \n",
       "4    male  35.0      0      0            373450   8.0500   NaN        S  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import LabelEncoder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>cabin</th>\n",
       "      <th>embarked</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>147</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>81</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>147</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>55</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>147</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   pclass  sex   age  sibsp  parch     fare  cabin  embarked\n",
       "0       3    1  22.0      1      0   7.2500    147         2\n",
       "1       1    0  38.0      1      0  71.2833     81         0\n",
       "2       3    0  26.0      0      0   7.9250    147         2\n",
       "3       1    0  35.0      1      0  53.1000     55         2\n",
       "4       3    1  35.0      0      0   8.0500    147         2"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.drop(labels=[\"name\", \"ticket\"], axis=1, inplace=True)\n",
    "\n",
    "X_train = df.loc[:,\"pclass\":]\n",
    "y_train = df[[\"survived\"]]\n",
    "\n",
    "LE = LabelEncoder()\n",
    "for feature in [\"sex\", \"cabin\", \"embarked\"]:\n",
    "    X_train[[feature]] = X_train[[feature]].astype(str)\n",
    "    LE.fit(X_train.loc[:,feature])\n",
    "    X_train[[feature]] = LE.transform(X_train.loc[:,feature])\n",
    "    \n",
    "X_train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived\n",
       "0         0\n",
       "1         1\n",
       "2         1\n",
       "3         1\n",
       "4         0"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>cabin</th>\n",
       "      <th>embarked</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>pclass</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.131900</td>\n",
       "      <td>-0.369226</td>\n",
       "      <td>0.083081</td>\n",
       "      <td>0.018443</td>\n",
       "      <td>-0.549500</td>\n",
       "      <td>0.684121</td>\n",
       "      <td>0.157112</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <td>0.131900</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.093254</td>\n",
       "      <td>-0.114631</td>\n",
       "      <td>-0.245489</td>\n",
       "      <td>-0.182333</td>\n",
       "      <td>0.096681</td>\n",
       "      <td>0.104057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>age</th>\n",
       "      <td>-0.369226</td>\n",
       "      <td>0.093254</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-0.308247</td>\n",
       "      <td>-0.189119</td>\n",
       "      <td>0.096067</td>\n",
       "      <td>-0.252331</td>\n",
       "      <td>-0.025252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sibsp</th>\n",
       "      <td>0.083081</td>\n",
       "      <td>-0.114631</td>\n",
       "      <td>-0.308247</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.414838</td>\n",
       "      <td>0.159651</td>\n",
       "      <td>0.043593</td>\n",
       "      <td>0.066654</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>parch</th>\n",
       "      <td>0.018443</td>\n",
       "      <td>-0.245489</td>\n",
       "      <td>-0.189119</td>\n",
       "      <td>0.414838</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.216225</td>\n",
       "      <td>-0.028324</td>\n",
       "      <td>0.038322</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>fare</th>\n",
       "      <td>-0.549500</td>\n",
       "      <td>-0.182333</td>\n",
       "      <td>0.096067</td>\n",
       "      <td>0.159651</td>\n",
       "      <td>0.216225</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-0.503355</td>\n",
       "      <td>-0.221226</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cabin</th>\n",
       "      <td>0.684121</td>\n",
       "      <td>0.096681</td>\n",
       "      <td>-0.252331</td>\n",
       "      <td>0.043593</td>\n",
       "      <td>-0.028324</td>\n",
       "      <td>-0.503355</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.193205</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>embarked</th>\n",
       "      <td>0.157112</td>\n",
       "      <td>0.104057</td>\n",
       "      <td>-0.025252</td>\n",
       "      <td>0.066654</td>\n",
       "      <td>0.038322</td>\n",
       "      <td>-0.221226</td>\n",
       "      <td>0.193205</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            pclass       sex       age     sibsp     parch      fare  \\\n",
       "pclass    1.000000  0.131900 -0.369226  0.083081  0.018443 -0.549500   \n",
       "sex       0.131900  1.000000  0.093254 -0.114631 -0.245489 -0.182333   \n",
       "age      -0.369226  0.093254  1.000000 -0.308247 -0.189119  0.096067   \n",
       "sibsp     0.083081 -0.114631 -0.308247  1.000000  0.414838  0.159651   \n",
       "parch     0.018443 -0.245489 -0.189119  0.414838  1.000000  0.216225   \n",
       "fare     -0.549500 -0.182333  0.096067  0.159651  0.216225  1.000000   \n",
       "cabin     0.684121  0.096681 -0.252331  0.043593 -0.028324 -0.503355   \n",
       "embarked  0.157112  0.104057 -0.025252  0.066654  0.038322 -0.221226   \n",
       "\n",
       "             cabin  embarked  \n",
       "pclass    0.684121  0.157112  \n",
       "sex       0.096681  0.104057  \n",
       "age      -0.252331 -0.025252  \n",
       "sibsp     0.043593  0.066654  \n",
       "parch    -0.028324  0.038322  \n",
       "fare     -0.503355 -0.221226  \n",
       "cabin     1.000000  0.193205  \n",
       "embarked  0.193205  1.000000  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "corrMatrix = X_train.corr()\n",
    "corrMatrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import LabelEncoder, MinMaxScaler\n",
    "from sklearn.model_selection import train_test_split"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_train, X_test, y_train, y_test = train_test_split(X_train, y_train.values.flatten(), test_size=0.25)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     pclass  sex   age  sibsp  parch      fare  cabin  embarked\n",
      "4         3    1  35.0      0      0    8.0500    147         2\n",
      "740       1    1   NaN      0      0   30.0000    105         2\n",
      "294       3    1  24.0      0      0    7.8958    147         2\n",
      "815       1    1   NaN      0      0    0.0000     16         2\n",
      "799       3    0  30.0      1      1   24.1500    147         2\n",
      "75        3    1  25.0      0      0    7.6500    140         2\n",
      "715       3    1  19.0      0      0    7.6500    140         2\n",
      "355       3    1  28.0      0      0    9.5000    147         2\n",
      "240       3    0   NaN      1      0   14.4542    147         0\n",
      "132       3    0  47.0      1      0   14.5000    147         2\n",
      "753       3    1  23.0      0      0    7.8958    147         2\n",
      "15        2    0  55.0      0      0   16.0000    147         2\n",
      "667       3    1   NaN      0      0    7.7750    147         2\n",
      "521       3    1  22.0      0      0    7.8958    147         2\n",
      "631       3    1  51.0      0      0    7.0542    147         2\n",
      "797       3    0  31.0      0      0    8.6833    147         2\n",
      "507       1    1   NaN      0      0   26.5500    147         2\n",
      "540       1    0  36.0      0      2   71.0000     20         2\n",
      "376       3    0  22.0      0      0    7.2500    147         2\n",
      "645       1    1  48.0      1      0   76.7292    101         0\n",
      "438       1    1  64.0      1      4  263.0000     63         2\n",
      "542       3    0  11.0      4      2   31.2750    147         2\n",
      "155       1    1  51.0      0      1   61.3792    147         0\n",
      "362       3    0  45.0      0      1   14.4542    147         0\n",
      "563       3    1   NaN      0      0    8.0500    147         2\n",
      "290       1    0  26.0      0      0   78.8500    147         2\n",
      "171       3    1   4.0      4      1   29.1250    147         1\n",
      "316       2    0  24.0      1      0   26.0000    147         2\n",
      "368       3    0   NaN      0      0    7.7500    147         1\n",
      "250       3    1   NaN      0      0    7.2500    147         2\n",
      "..      ...  ...   ...    ...    ...       ...    ...       ...\n",
      "855       3    0  18.0      0      1    9.3500    147         2\n",
      "1         1    0  38.0      1      0   71.2833     81         0\n",
      "627       1    0  21.0      0      0   77.9583    114         2\n",
      "456       1    1  65.0      0      0   26.5500    126         2\n",
      "320       3    1  22.0      0      0    7.2500    147         2\n",
      "344       2    1  36.0      0      0   13.0000    147         2\n",
      "354       3    1   NaN      0      0    7.2250    147         0\n",
      "813       3    0   6.0      4      2   31.2750    147         2\n",
      "367       3    0   NaN      0      0    7.2292    147         0\n",
      "148       2    1  36.5      0      2   26.0000    141         2\n",
      "213       2    1  30.0      0      0   13.0000    147         2\n",
      "181       2    1   NaN      0      0   15.0500    147         0\n",
      "766       1    1   NaN      0      0   39.6000    147         0\n",
      "168       1    1   NaN      0      0   25.9250    147         2\n",
      "535       2    0   7.0      0      2   26.2500    147         2\n",
      "510       3    1  29.0      0      0    7.7500    147         1\n",
      "380       1    0  42.0      0      0  227.5250    147         0\n",
      "31        1    0   NaN      1      0  146.5208     41         0\n",
      "150       2    1  51.0      0      0   12.5250    147         2\n",
      "610       3    0  39.0      1      5   31.2750    147         2\n",
      "882       3    0  22.0      0      0   10.5167    147         2\n",
      "538       3    1   NaN      0      0   14.5000    147         2\n",
      "337       1    0  41.0      0      0  134.5000    127         0\n",
      "276       3    0  45.0      0      0    7.7500    147         2\n",
      "780       3    0  13.0      0      0    7.2292    147         0\n",
      "205       3    0   2.0      0      1   10.4625    145         2\n",
      "883       2    1  28.0      0      0   10.5000    147         2\n",
      "167       3    0  45.0      1      4   27.9000    147         2\n",
      "437       2    0  24.0      2      3   18.7500    147         2\n",
      "448       3    0   5.0      2      1   19.2583    147         0\n",
      "\n",
      "[668 rows x 8 columns]\n"
     ]
    }
   ],
   "source": [
    "print(X_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.neighbors import KNeighborsClassifier\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "knn = KNeighborsClassifier()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "Input contains NaN, infinity or a value too large for dtype('float64').",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-40-61e60d6f11e8>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mresultado\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mknn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_test\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m~/miniconda3/envs/aula/lib/python3.6/site-packages/sklearn/neighbors/classification.py\u001b[0m in \u001b[0;36mpredict\u001b[0;34m(self, X)\u001b[0m\n\u001b[1;32m    141\u001b[0m             \u001b[0mClass\u001b[0m \u001b[0mlabels\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0meach\u001b[0m \u001b[0mdata\u001b[0m \u001b[0msample\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    142\u001b[0m         \"\"\"\n\u001b[0;32m--> 143\u001b[0;31m         \u001b[0mX\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcheck_array\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maccept_sparse\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'csr'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    144\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    145\u001b[0m         \u001b[0mneigh_dist\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mneigh_ind\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkneighbors\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/miniconda3/envs/aula/lib/python3.6/site-packages/sklearn/utils/validation.py\u001b[0m in \u001b[0;36mcheck_array\u001b[0;34m(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)\u001b[0m\n\u001b[1;32m    451\u001b[0m                              % (array.ndim, estimator_name))\n\u001b[1;32m    452\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mforce_all_finite\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 453\u001b[0;31m             \u001b[0m_assert_all_finite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    454\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    455\u001b[0m     \u001b[0mshape_repr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_shape_repr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/miniconda3/envs/aula/lib/python3.6/site-packages/sklearn/utils/validation.py\u001b[0m in \u001b[0;36m_assert_all_finite\u001b[0;34m(X)\u001b[0m\n\u001b[1;32m     42\u001b[0m             and not np.isfinite(X).all()):\n\u001b[1;32m     43\u001b[0m         raise ValueError(\"Input contains NaN, infinity\"\n\u001b[0;32m---> 44\u001b[0;31m                          \" or a value too large for %r.\" % X.dtype)\n\u001b[0m\u001b[1;32m     45\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     46\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mValueError\u001b[0m: Input contains NaN, infinity or a value too large for dtype('float64')."
     ]
    }
   ],
   "source": [
    "resultado = knn.predict(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     pclass  sex   age  sibsp  parch      fare  cabin  embarked\n",
      "840       3    1  20.0      0      0    7.9250    147         2\n",
      "612       3    0   NaN      1      0   15.5000    147         1\n",
      "679       1    1  36.0      0      1  512.3292     34         0\n",
      "745       1    1  70.0      1      1   71.0000     20         2\n",
      "761       3    1  41.0      0      0    7.1250    147         2\n",
      "734       2    1  23.0      0      0   13.0000    147         2\n",
      "340       2    1   2.0      1      1   26.0000    141         2\n",
      "736       3    0  48.0      1      3   34.3750    147         2\n",
      "427       2    0  19.0      0      0   26.0000    147         2\n",
      "649       3    0  23.0      0      0    7.5500    147         2\n",
      "114       3    0  17.0      0      0   14.4583    147         0\n",
      "203       3    1  45.5      0      0    7.2250    147         0\n",
      "530       2    0   2.0      1      1   26.0000    147         2\n",
      "402       3    0  21.0      1      0    9.8250    147         2\n",
      "361       2    1  29.0      1      0   27.7208    147         0\n",
      "796       1    0  49.0      0      0   25.9292     94         2\n",
      "514       3    1  24.0      0      0    7.4958    147         2\n",
      "750       2    0   4.0      1      1   23.0000    147         2\n",
      "733       2    1  23.0      0      0   13.0000    147         2\n",
      "594       2    1  37.0      1      0   26.0000    147         2\n",
      "672       2    1  70.0      0      0   10.5000    147         2\n",
      "570       2    1  62.0      0      0   10.5000    147         2\n",
      "814       3    1  30.5      0      0    8.0500    147         2\n",
      "571       1    0  53.0      2      0   51.4792     48         2\n",
      "218       1    0  32.0      0      0   76.2917     93         0\n",
      "694       1    1  60.0      0      0   26.5500    147         2\n",
      "849       1    0   NaN      1      0   89.1042     86         0\n",
      "775       3    1  18.0      0      0    7.7500    147         2\n",
      "547       2    1   NaN      0      0   13.8625    147         0\n",
      "857       1    1  51.0      0      0   26.5500    119         2\n",
      "..      ...  ...   ...    ...    ...       ...    ...       ...\n",
      "61        1    0  38.0      0      0   80.0000     21         3\n",
      "683       3    1  14.0      5      2   46.9000    147         2\n",
      "458       2    0  50.0      0      0   10.5000    147         2\n",
      "217       2    1  42.0      1      0   27.0000    147         2\n",
      "451       3    1   NaN      1      0   19.9667    147         2\n",
      "787       3    1   8.0      4      1   29.1250    147         1\n",
      "109       3    0   NaN      1      0   24.1500    147         1\n",
      "634       3    0   9.0      3      2   27.9000    147         2\n",
      "588       3    1  22.0      0      0    8.0500    147         2\n",
      "699       3    1  42.0      0      0    7.6500    139         2\n",
      "580       2    0  25.0      1      1   30.0000    147         2\n",
      "886       2    1  27.0      0      0   13.0000    147         2\n",
      "724       1    1  27.0      1      0   53.1000    137         2\n",
      "164       3    1   1.0      4      1   39.6875    147         2\n",
      "184       3    0   4.0      0      2   22.0250    147         2\n",
      "42        3    1   NaN      0      0    7.8958    147         0\n",
      "430       1    1  28.0      0      0   26.5500     71         2\n",
      "767       3    0  30.5      0      0    7.7500    147         1\n",
      "145       2    1  19.0      1      1   36.7500    147         2\n",
      "388       3    1   NaN      0      0    7.7292    147         1\n",
      "359       3    0   NaN      0      0    7.8792    147         1\n",
      "470       3    1   NaN      0      0    7.2500    147         2\n",
      "127       3    1  24.0      0      0    7.1417    147         2\n",
      "472       2    0  33.0      1      2   27.7500    147         2\n",
      "519       3    1  32.0      0      0    7.8958    147         2\n",
      "490       3    1   NaN      1      0   19.9667    147         2\n",
      "420       3    1   NaN      0      0    7.8958    147         0\n",
      "825       3    1   NaN      0      0    6.9500    147         1\n",
      "96        1    1  71.0      0      0   34.6542     12         0\n",
      "711       1    1   NaN      0      0   26.5500     56         2\n",
      "\n",
      "[223 rows x 8 columns]\n"
     ]
    }
   ],
   "source": [
    "print(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_test[\"age\"] = X_test.age.fillna(X_test.age.mean())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     pclass  sex        age  sibsp  parch      fare  cabin  embarked\n",
      "840       3    1  20.000000      0      0    7.9250    147         2\n",
      "612       3    0  30.376229      1      0   15.5000    147         1\n",
      "679       1    1  36.000000      0      1  512.3292     34         0\n",
      "745       1    1  70.000000      1      1   71.0000     20         2\n",
      "761       3    1  41.000000      0      0    7.1250    147         2\n",
      "734       2    1  23.000000      0      0   13.0000    147         2\n",
      "340       2    1   2.000000      1      1   26.0000    141         2\n",
      "736       3    0  48.000000      1      3   34.3750    147         2\n",
      "427       2    0  19.000000      0      0   26.0000    147         2\n",
      "649       3    0  23.000000      0      0    7.5500    147         2\n",
      "114       3    0  17.000000      0      0   14.4583    147         0\n",
      "203       3    1  45.500000      0      0    7.2250    147         0\n",
      "530       2    0   2.000000      1      1   26.0000    147         2\n",
      "402       3    0  21.000000      1      0    9.8250    147         2\n",
      "361       2    1  29.000000      1      0   27.7208    147         0\n",
      "796       1    0  49.000000      0      0   25.9292     94         2\n",
      "514       3    1  24.000000      0      0    7.4958    147         2\n",
      "750       2    0   4.000000      1      1   23.0000    147         2\n",
      "733       2    1  23.000000      0      0   13.0000    147         2\n",
      "594       2    1  37.000000      1      0   26.0000    147         2\n",
      "672       2    1  70.000000      0      0   10.5000    147         2\n",
      "570       2    1  62.000000      0      0   10.5000    147         2\n",
      "814       3    1  30.500000      0      0    8.0500    147         2\n",
      "571       1    0  53.000000      2      0   51.4792     48         2\n",
      "218       1    0  32.000000      0      0   76.2917     93         0\n",
      "694       1    1  60.000000      0      0   26.5500    147         2\n",
      "849       1    0  30.376229      1      0   89.1042     86         0\n",
      "775       3    1  18.000000      0      0    7.7500    147         2\n",
      "547       2    1  30.376229      0      0   13.8625    147         0\n",
      "857       1    1  51.000000      0      0   26.5500    119         2\n",
      "..      ...  ...        ...    ...    ...       ...    ...       ...\n",
      "61        1    0  38.000000      0      0   80.0000     21         3\n",
      "683       3    1  14.000000      5      2   46.9000    147         2\n",
      "458       2    0  50.000000      0      0   10.5000    147         2\n",
      "217       2    1  42.000000      1      0   27.0000    147         2\n",
      "451       3    1  30.376229      1      0   19.9667    147         2\n",
      "787       3    1   8.000000      4      1   29.1250    147         1\n",
      "109       3    0  30.376229      1      0   24.1500    147         1\n",
      "634       3    0   9.000000      3      2   27.9000    147         2\n",
      "588       3    1  22.000000      0      0    8.0500    147         2\n",
      "699       3    1  42.000000      0      0    7.6500    139         2\n",
      "580       2    0  25.000000      1      1   30.0000    147         2\n",
      "886       2    1  27.000000      0      0   13.0000    147         2\n",
      "724       1    1  27.000000      1      0   53.1000    137         2\n",
      "164       3    1   1.000000      4      1   39.6875    147         2\n",
      "184       3    0   4.000000      0      2   22.0250    147         2\n",
      "42        3    1  30.376229      0      0    7.8958    147         0\n",
      "430       1    1  28.000000      0      0   26.5500     71         2\n",
      "767       3    0  30.500000      0      0    7.7500    147         1\n",
      "145       2    1  19.000000      1      1   36.7500    147         2\n",
      "388       3    1  30.376229      0      0    7.7292    147         1\n",
      "359       3    0  30.376229      0      0    7.8792    147         1\n",
      "470       3    1  30.376229      0      0    7.2500    147         2\n",
      "127       3    1  24.000000      0      0    7.1417    147         2\n",
      "472       2    0  33.000000      1      2   27.7500    147         2\n",
      "519       3    1  32.000000      0      0    7.8958    147         2\n",
      "490       3    1  30.376229      1      0   19.9667    147         2\n",
      "420       3    1  30.376229      0      0    7.8958    147         0\n",
      "825       3    1  30.376229      0      0    6.9500    147         1\n",
      "96        1    1  71.000000      0      0   34.6542     12         0\n",
      "711       1    1  30.376229      0      0   26.5500     56         2\n",
      "\n",
      "[223 rows x 8 columns]\n"
     ]
    }
   ],
   "source": [
    "print(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.neighbors import KNeighborsClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "Input contains NaN, infinity or a value too large for dtype('float64').",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-47-889312abc571>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mknn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_train\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0my_train\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m~/miniconda3/envs/aula/lib/python3.6/site-packages/sklearn/neighbors/base.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, X, y)\u001b[0m\n\u001b[1;32m    763\u001b[0m         \"\"\"\n\u001b[1;32m    764\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mKDTree\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mBallTree\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 765\u001b[0;31m             \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcheck_X_y\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"csr\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmulti_output\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    766\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    767\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m1\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m2\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/miniconda3/envs/aula/lib/python3.6/site-packages/sklearn/utils/validation.py\u001b[0m in \u001b[0;36mcheck_X_y\u001b[0;34m(X, y, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)\u001b[0m\n\u001b[1;32m    571\u001b[0m     X = check_array(X, accept_sparse, dtype, order, copy, force_all_finite,\n\u001b[1;32m    572\u001b[0m                     \u001b[0mensure_2d\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mallow_nd\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mensure_min_samples\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 573\u001b[0;31m                     ensure_min_features, warn_on_dtype, estimator)\n\u001b[0m\u001b[1;32m    574\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mmulti_output\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    575\u001b[0m         y = check_array(y, 'csr', force_all_finite=True, ensure_2d=False,\n",
      "\u001b[0;32m~/miniconda3/envs/aula/lib/python3.6/site-packages/sklearn/utils/validation.py\u001b[0m in \u001b[0;36mcheck_array\u001b[0;34m(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)\u001b[0m\n\u001b[1;32m    451\u001b[0m                              % (array.ndim, estimator_name))\n\u001b[1;32m    452\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mforce_all_finite\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 453\u001b[0;31m             \u001b[0m_assert_all_finite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    454\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    455\u001b[0m     \u001b[0mshape_repr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_shape_repr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/miniconda3/envs/aula/lib/python3.6/site-packages/sklearn/utils/validation.py\u001b[0m in \u001b[0;36m_assert_all_finite\u001b[0;34m(X)\u001b[0m\n\u001b[1;32m     42\u001b[0m             and not np.isfinite(X).all()):\n\u001b[1;32m     43\u001b[0m         raise ValueError(\"Input contains NaN, infinity\"\n\u001b[0;32m---> 44\u001b[0;31m                          \" or a value too large for %r.\" % X.dtype)\n\u001b[0m\u001b[1;32m     45\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     46\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mValueError\u001b[0m: Input contains NaN, infinity or a value too large for dtype('float64')."
     ]
    }
   ],
   "source": [
    "knn.fit(X_train,y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_train[\"age\"] = X_train.age.fillna(X_train.age.mean())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 1 1 0 0 0 0 0 1 0 1 1 0 1 1 1 0 0 0 0\n",
      " 1 0 0 0 0 1 0 0 0 0 1 0 1 1 1 0 0 1 1 0 0 1 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0\n",
      " 0 1 0 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1 0\n",
      " 0 0 0 0 0 1 0 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 0 1 0 0 1 1 1 0 1 0 0 0 0 1 0\n",
      " 1 0 1 0 0 1 0 1 0 0 0 1 0 1 1 1 1 0 0 0 0 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 1\n",
      " 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 0 0 0 0 0 1 1 1 1 0 0 0 0 1 0 1 0 0 0\n",
      " 1 1]\n"
     ]
    }
   ],
   "source": [
    "print(y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',\n",
       "           metric_params=None, n_jobs=1, n_neighbors=5, p=2,\n",
       "           weights='uniform')"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "knn.fit(X_train,y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "res = knn.predict(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics import accuracy_score, classification_report"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.69955156950672648"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "accuracy_score(y_test, res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "scores = []\n",
    "ks = range(1,120, 4)\n",
    "n_ks = len(ks)\n",
    "\n",
    "for k in ks:\n",
    "    knn = KNeighborsClassifier(n_neighbors=k)\n",
    "    knn.fit(X_train,y_train)\n",
    "    scores.append(knn.score(X_test,y_test))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/jader/miniconda3/envs/aula/lib/python3.6/site-packages/matplotlib/font_manager.py:281: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.\n",
      "  'Matplotlib is building the font cache using fc-list. '\n"
     ]
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAIABJREFUeJzt3XecFFW2wPHfIQwgKKDoSJAk6IoJHEUx+4zorrirIpjAdWXdfYaHOa2iT13TmtFnBhUJa0BWUXR1MIIKgiggCKwKgoAKwiB5zvvjVls1Tc9090xXV4fz/Xz6Y93qCvfSY5+uG0VVMcYYY2pSL+oMGGOMyX0WLIwxxiRlwcIYY0xSFiyMMcYkZcHCGGNMUhYsjDHGJGXBwhhjTFIWLIwxxiRlwcIYY0xSDaLOQKa0atVKO3bsmNY5a9asoWnTpuFkKCKFViYrT+4rtDIVWnmg5jJNnTr1B1XdPtk1CiZYdOzYkSlTpqR1zsSJEzn88MPDyVBECq1MVp7cV2hlKrTyQM1lEpFvUrmGVUMZY4xJyoKFMcaYpCxYGGOMScqChTHGmKQsWBhjjEnKgoUxxpikLFjkCVWYORN++SXqnBhjipEFizxxySWwxx6w336wbl3UuTHGFBsLFnlg0yZ4/HG3PWsWjB0bbX6MMcXHgkUemDYNKir89PDh0eXFGFOcLFjkgYkTq6bfeAMWL44kK8aYImXBIg+8807VdGUljBgRTV6MMcXJgkWO27wZ3ntvy/3DhrkeUsYYkw0WLHLc9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Sp8C+A3CLZn0gItNxcwl1iDuvJ/COqv6kbtK9f8a9P1ZVK70qq9LA/o/VrbOyGTeFw8HAfsBEdRP4xWYPPdQ7fjNuMkmAVcA64HER+QMQnA/ImDqxYGGKUSXQF/cL/ZqaDvS+nP+Bm5AtRoA3VbW79+qmqvGBJ9E00EHrqzk2fv4dTXKtdV5gieW1Jy54nAS8niQPxqTMgoUpSupm4fwtcIaIJHvCGIabnnt7Lz0ZOEhEugB4s7DuEnfOx8BhItLSm7775BSz1tObDbkecBrwPm5Rq8NEpJXXiN0feCf+RK/dpLmqjgf+B1dlZUxGNEh+iDGFSVV/8qZxfldEflDVhFNrq+oGEbkft542qrpcRAYCI0WkkXfYdbhZjGPnfCcit+K+6Bfj2hN+TiFbk3BtGHsC7wIvqWqliFyNmwpcgPHV5HVr4GURaewdNziF+xmTEpt11piQiEgzVa3wnixeAp5U1ZeizpcxtWHVUMaEZ4jXAP4F8B/cehbG5CV7sjDGGJOUPVkYY4xJyoKFMcaYpCxYGGOMScqChTHGmKQsWBhjjEnKgoUxxpik/h9UZx5L1hAu/AAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f5f959bdac8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig,ax = plt.subplots()\n",
    "ax.plot(ks,scores,'b',linewidth=3)\n",
    "ax.set_ylabel('Accuracy')\n",
    "ax.set_xlabel('K Neighbors')\n",
    "\n",
    "plt.grid()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.75336322869955152"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "max(scores)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6905829596412556"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "min(scores)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "17"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bestK = scores.index(max(scores))\n",
    "\n",
    "bestK = bestK*4 +1\n",
    "bestK"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',\n",
       "           metric_params=None, n_jobs=1, n_neighbors=17, p=2,\n",
       "           weights='uniform')"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "knn = KNeighborsClassifier(n_neighbors=bestK)\n",
    "knn.fit(X_train,y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "result = knn.predict(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "report = classification_report(knn.predict(X_test), y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             precision    recall  f1-score   support\n",
      "\n",
      "          0       0.90      0.75      0.82       164\n",
      "          1       0.52      0.76      0.62        59\n",
      "\n",
      "avg / total       0.80      0.75      0.77       223\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(report)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'KNNClassifier' object has no attribute 'k_closest'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-83-43abed96e70f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mpred\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mknn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_test\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbestK\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m<ipython-input-32-2c3c974d5e2c>\u001b[0m in \u001b[0;36mpredict\u001b[0;34m(self, to_classify, k)\u001b[0m\n\u001b[1;32m     27\u001b[0m         \u001b[0mpredictions\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     28\u001b[0m         \u001b[0;32mfor\u001b[0m \u001b[0mrow\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mto_classify\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 29\u001b[0;31m             \u001b[0mlabel\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mk_closest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrow\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     30\u001b[0m             \u001b[0mpredictions\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     31\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mAttributeError\u001b[0m: 'KNNClassifier' object has no attribute 'k_closest'"
     ]
    }
   ],
   "source": [
    "pred = knn.predict(X_test, bestK)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.neighbors import DistanceMetric\n",
    "\n",
    "class KNNClassifier(object):\n",
    "    def __init__(self, n=1):\n",
    "        self.X_train = None\n",
    "        self.Y_train = None\n",
    "        self.n = n\n",
    "        \n",
    "    def dist_euc(self, a, b):\n",
    "        dist = DistanceMetric.get_metric('euclidean').pairwise([a],[b])[0][0]\n",
    "        return dist\n",
    "    \n",
    "    def closest(self, row, k):\n",
    "        dist = [(self.dist_euc(row, item)) for index,item in enumerate(self.X_train)]\n",
    "        dist.sort(key = lambda x:x[1])\n",
    "        viz = []\n",
    "        for i in range(k):\n",
    "            viz.append(self.Y_train[dist[i][0]])\n",
    "            \n",
    "        classe = Counter(viz).most_common(1)[0][0]\n",
    "        \n",
    "        return classe\n",
    "    \n",
    "    def fit(self, training_data, training_labels):\n",
    "        self.X_train = training_data\n",
    "        self.Y_train = training_labels\n",
    "        \n",
    "    def predict(self, to_classify, k=3):\n",
    "        predictions = []\n",
    "        for row in to_classify:\n",
    "            label = self.closest(row,k)\n",
    "            predictions.append(label)\n",
    "            \n",
    "        return predictions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [],
   "source": [
    "knn = KNNClassifier()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [],
   "source": [
    "knn.fit(X_train.values, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "invalid index to scalar variable.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-92-ef7f9bfce8a0>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mres2\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0mknn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_test\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mk\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mbestK\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m<ipython-input-89-c2b1ce33cba4>\u001b[0m in \u001b[0;36mpredict\u001b[0;34m(self, to_classify, k)\u001b[0m\n\u001b[1;32m     29\u001b[0m         \u001b[0mpredictions\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     30\u001b[0m         \u001b[0;32mfor\u001b[0m \u001b[0mrow\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mto_classify\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 31\u001b[0;31m             \u001b[0mlabel\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclosest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrow\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     32\u001b[0m             \u001b[0mpredictions\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     33\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-89-c2b1ce33cba4>\u001b[0m in \u001b[0;36mclosest\u001b[0;34m(self, row, k)\u001b[0m\n\u001b[1;32m     13\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mclosest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrow\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     14\u001b[0m         \u001b[0mdist\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdist_euc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrow\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mitem\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mitem\u001b[0m \u001b[0;32min\u001b[0m \u001b[0menumerate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mX_train\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 15\u001b[0;31m         \u001b[0mdist\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msort\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     16\u001b[0m         \u001b[0mviz\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     17\u001b[0m         \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-89-c2b1ce33cba4>\u001b[0m in \u001b[0;36m<lambda>\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m     13\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mclosest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrow\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     14\u001b[0m         \u001b[0mdist\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdist_euc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrow\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mitem\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mitem\u001b[0m \u001b[0;32min\u001b[0m \u001b[0menumerate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mX_train\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 15\u001b[0;31m         \u001b[0mdist\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msort\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     16\u001b[0m         \u001b[0mviz\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     17\u001b[0m         \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mIndexError\u001b[0m: invalid index to scalar variable."
     ]
    }
   ],
   "source": [
    "res2= knn.predict(X_test.values, k=bestK)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "tentei!!! ;/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
